<?php
namespace App\SMS;

class SendTemplateSMS{
    //主帐号
    private $accountSid= '8a48b5514a61a814014a6b4bbbf4039e';

    //主帐号Token
    private $accountToken= '909ce0f78e9f4a66beaec16f55288410';

    //应用Id
    private $appId='8aaf07085a6ec238015aa6ead95817b7';

    //请求地址，格式如下，不需要写https://
    private $serverIP='app.cloopen.com';

    //请求端口
    private $serverPort='8883';

    //REST版本号
    private $softVersion='2013-12-26';

    public function SendSMS($to,$datas,$tempId){
        $rest = new REST($this->serverIP,$this->serverPort,$this->softVersion);
        $rest->setAccount($this->accountSid,$this->accountToken);
        $rest->setAppId($this->appId);

        // 发送模板短信
//        echo "Sending TemplateSMS to $to <br/>";
        $result = $rest->sendTemplateSMS($to,$datas,$tempId);
        if($result == NULL || $result->statusCode!=0) {
//            return "error code :" . $result->statusCode . "<br>error msg :" . $result->statusMsg . "<br>";
            return 0;
        }else{
//            echo "Sendind TemplateSMS success!<br/>";
            // 获取返回信息
//            $smsmessage = $result->TemplateSMS;
//            return "dateCreated:".$smsmessage->dateCreated."<br/>smsMessageSid:".$smsmessage->smsMessageSid."<br/>";
            return 1;
        }
    }
}